package net.goutalk.glcs.common.runner;

import net.goutalk.glcs.module.liteflow.entity.LiteflowChain;
import net.goutalk.glcs.module.liteflow.service.ILiteflowChainService;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: tanyujie
 * @Date: 2023/4/7 10:41
 */
@Component
@AllArgsConstructor
@Slf4j
public class LiteflowRunner  implements CommandLineRunner {

    private ILiteflowChainService liteflowChainService;

    @Override
    public void run(String... args) {
        log.info("GLCS: 加载所有规则开始");
        List<LiteflowChain> list = liteflowChainService.list();

        for (LiteflowChain liteflowChain : list) {
            LiteFlowChainELBuilder.createChain().setChainId(liteflowChain.getChainName()).setEL(liteflowChain.getElData()).build();
        }
        log.info("GLCS: 加载所有规则结束");
    }
}
